package com.server.util;

import java.io.InputStream;
import java.util.Properties;

public class ConfPropertiesUtil {

    private static final ConfPropertiesUtil instance = new ConfPropertiesUtil();

    public static ConfPropertiesUtil getInstance() {
        return instance;
    }

    Properties properties = new Properties();

    public int _PORT;
    public boolean _DEBUG;
    public int _MSG_THREAD_NUM;
    public int _SERVER_ID;

    public void init() throws Exception {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        InputStream inStream = loader.getResourceAsStream("properties");//加载resources目录的配置文件
        properties.load(inStream);
        _PORT = Integer.valueOf(properties.getProperty("_PORT"));
        _DEBUG = Boolean.parseBoolean(properties.getProperty("_DEBUG"));
        _MSG_THREAD_NUM = Integer.valueOf(properties.getProperty("_MSG_THREAD_NUM"));
        _SERVER_ID = Integer.valueOf(properties.getProperty("_SERVER_ID"));
    }

    public final Properties getProperties() {
        return this.properties;
    }

    /**
     * 重新加载接口
     */
    public void reload() {
        try {
            init();
        } catch (Exception e) {
            LogUtil.game.error("Exception", e);
        }
    }
}
